function refreshElement(element, page){
    new Ajax.Updater(element, page, { method: 'get' });
}
//****************  script for new otc items implementing scriptaculosus ***************
Event.observe(window, 'load', function(){
    
    new Ajax.Autocompleter("autocomplete_jrv", "autocomplete_choices", "documentServlet",  
    {
        minChars : 7,
        callback: function(element, entry) {
            //alert('test2');
            //"&town=" + $("docForm:townsCombo").value + 
            //"&ballot=" + $("docForm:ballotsCombo").value +             
            return entry + "&counting=" + $("docForm:counting").value +
            "&operation=" + $("docForm:operation").value +
            "&electionType=" + $("docForm:electionType").value;
        },
        afterUpdateElement : getSelectionId
    });
    
    new Ajax.Autocompleter("docForm:fiscalName", "fiscal_choices", "fiscalServlet",  
    {
        minChars : 5,
        callback: function(element, entry) {       
            return entry + "&fiscalName=" + $("docForm:fiscalName").value;
        }
    });
});


function getSelectionId(text, li) {
    //alert('test selection');
    var st = li.id;
    var fd = text.name;
    var op = $("docForm:operation").value;
    new Ajax.Request('documentValidateServlet', {
        method:'get',
        asynchronous: false,
        parameters: {
            id: st, 
            field : fd
        },
        onSuccess: function(transport){
            var response = transport.responseText.evalJSON();
            var item = response.junta;
            var frm = 'docForm';
            if(fd == 'autocomplete_jrv'){
                if (op == 'VERIFICATION'){
                    $(frm + ':jrvHidden').value = st;
                    $(frm + ':search').click();
                }
                $(frm + ':jrvHidden').value = st;
                $(frm + ':townName').value = item.townName;
                $(frm + ':ballotDesc').value = item.ballotDesc;     
            }
        },
        onFailure: function(){    
            alert('Falla de conexion. Pruebe de nuevo.');
        }
        
    });
}